<template>
  <div class="tooltip-wrapper" @mouseenter="showTip" @mouseleave="hideTip">
    <slot></slot>
    <div v-show="visible" 
         class="tooltip" 
         :class="[placement]"
         ref="tooltip">
      {{ content }}
    </div>
  </div>
</template>

<script>
export default {
  name: 'Tooltip',
  props: {
    content: {
      type: String,
      required: true
    },
    placement: {
      type: String,
      default: 'top',
      validator: function(value) {
        return ['top', 'bottom', 'left', 'right'].indexOf(value) !== -1
      }
    }
  },
  data() {
    return {
      visible: false
    }
  },
  methods: {
    showTip() {
      this.visible = true
    },
    hideTip() {
      this.visible = false
    }
  }
}
</script>

<style lang="scss" scoped>
.tooltip-wrapper {
  position: relative;
  display: inline-block;
}

.tooltip {
  position: absolute;
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.75);
  color: white;
  border-radius: 4px;
  font-size: 14px;
  z-index: 1000;
  max-width: 300px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.4;
  
  // 上方显示
  &.top {
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-10px);
    min-width: max-content;
  }
  
  // 下方显示
  &.bottom {
    top: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    min-width: max-content;
  }
  
  // 左侧显示
  &.left {
    right: 100%;
    top: 50%;
    transform: translateY(-50%) translateX(-10px);
    min-width: max-content;
  }
  
  // 右侧显示
  &.right {
    left: 100%;
    top: 50%;
    transform: translateY(-50%) translateX(10px);
    min-width: max-content;
  }
}
</style> 